﻿using System.Threading.Tasks;

namespace XnReader.WinRT.Helper
{
    public class GlobalUtils
    {
        public static string GetSortName(int sortid)
        {
            switch (sortid)
            {
                case 101:
                    return "全本";
                case 1:
                    return "玄幻奇幻";
                case 2:
                    return "武侠仙侠";
                case 3:
                    return "都市言情";
                case 4:
                    return "历史军事";
                case 5:
                    return "游戏竞技";
                case 6:
                    return "科幻灵异";
                case 7:
                    return "漫画同人";
                default:
                    return "查询结果";
            }
        }

        public static void SaveKey(string key, object obj)
        {
            Windows.Storage.ApplicationDataContainer setting =
                Windows.Storage.ApplicationData.Current.LocalSettings;

            setting.Values[key] = obj;
        }

        public static object GetValue(string key)
        {
            Windows.Storage.ApplicationDataContainer setting =
                Windows.Storage.ApplicationData.Current.LocalSettings;
            if (setting.Values.ContainsKey(key))
            {
                return setting.Values[key];
            }
            return null;
        }

        /// <summary>
        /// 判断网络链接?san内网存在，外网不存在时无法判断
        /// </summary>
        /// <returns></returns>
        public static async Task<bool> CheckConnectionState()
        {
            var connectionProfile = Windows.Networking.Connectivity.NetworkInformation.GetInternetConnectionProfile();
            return connectionProfile != null;
        }
    }
}
